#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    w=200;
    imgInit();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::imgInit()
{
    Mat imgData = Mat::zeros(w,w,CV_8UC3);
    cvtColor(imgData,imgData,COLOR_BGR2RGB);
    myImg=imgData;
    myQImg = QImage((const uchar*)(imgData.data),imgData.cols,imgData.rows,QImage::Format_RGB888);
    imgShow();
}

void MainWindow::imgShow()
{
    ui->label->setPixmap(QPixmap::fromImage(myQImg.scaled(ui->label->size())));
}

void MainWindow::MyEllipse(Mat img, double angle)
{
    int thickness = 1;
    int lineType = 8;

    cv::ellipse(img,Point(w/2,w/2),Size(w/4,w/16),angle,0,360,Scalar(0,0,255),thickness,lineType);
}

void MainWindow::MyFilledCircle(Mat img, Point center)
{
    int thickness = -1; //填充
    int lineType = 8;

    cv::circle(img,center,w/32,Scalar(255,0,0),thickness,lineType);
}


void MainWindow::on_btnDraw_clicked()
{
    /// 1.a. 创建椭圆
    MyEllipse( myImg, 90 );
    MyEllipse( myImg, 0 );
    MyEllipse( myImg, 45 );
    MyEllipse( myImg, -45 );

    /// 1.b. 创建圆
    MyFilledCircle( myImg, Point( w/2.0, w/2.0) );

    myQImg = QImage((const uchar*)(myImg.data),myImg.cols,myImg.rows,QImage::Format_RGB888);
    imgShow();
}

